package com.ts.mapper.achievement;


import com.ts.entity.TsAchievement;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.SelectKey;

@Mapper
public interface TsAchievementMapper {

    @Insert("INSERT INTO ts_achievement " +
            "(name, type, status, description, level, detail_id, " +
            "created_by, updated_by, created_time, updated_time) VALUES (" +
            "#{name}, #{type}, #{status}, #{description}, #{level}, #{detailId}, " +
            "#{createdBy}, #{updatedBy}, #{createdTime}, #{updatedTime})")
            @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    // 关键：插入后查询自增ID，并赋值给实体的id字段
    @SelectKey(
            statement = "SELECT LAST_INSERT_ID()", // MySQL获取自增ID的函数
            keyProperty = "id", // 要赋值的实体属性（对应TsAchievement的id字段）
            before = false, // false表示插入后执行查询
            resultType = Integer.class // ID的类型（与实体类id字段一致）
    )
    int insert(TsAchievement tsAchievement);
}
